<%--
  Created by IntelliJ IDEA.
  User: Aaking-aline
  Date: 2022-05-23
  Time: 8:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<title>注册页</title>
	</head>
	<body>
		<center>
			<form id="form1" action="#">
				账号:<input type="text" id="username" name="username"> <br> <br>
				密码:<input type="text" id="password" name="password"> <br> <br>
				年龄:<input type="text" id="age" name="age"> <br> <br>
				邮箱:<input type="text" id="email" name="email"> <br> <br>
				电话:<input type="text" id="phone" name="phone"> <br> <br>

				<input type="button" value="注册" onclick="zc()">
			</form>
		</center>
	</body>

	<script>
		function zc(){
			//-------------------------验证账号-------------------------------------------
			let usernameValue = document.getElementById("username").value;
			let usernameRegex = /(^\w+@\w+\.\w+$)|(^1[3578][0-9]{9}$)/;
			if(!usernameRegex.test(usernameValue)){
				alert("注册账号必须是邮箱或手机号");
				return;
			}
			//--------------------------验证密码------------------------------------------
			let passwordValue = document.getElementById("password").value;
			let passwordRegex = /^[0-9a-z]{4,15}$/;
			if(!passwordRegex.test(passwordValue)){
				alert("注册密码必须大于4位并且小于15位");
				return;
			}
			//--------------------------验证年龄------------------------------------------
			let ageValue = document.getElementById("age").value;
			let ageRegex = /^[1-9]{0,1}[0-9]{1}$/;
			if(!ageRegex.test(ageValue)){
				alert("请输入正确的年龄");
				return;
			}
			//---------------------------验证邮箱-----------------------------------------
			let emailValue = document.getElementById("email").value;
			let emailRegex = /^\w+@\w+\.\w+$/;
			if(!emailRegex.test(emailValue)){
				alert("请输入正确的邮箱");
				return;
			}
			//---------------------------验证手机-----------------------------------------
			let phoneValue = document.getElementById("phone").value;
			let phoneRegex = /^1[3578][0-9]{9}$/;
			if(!phoneRegex.test(phoneValue)){
				alert("请输入正确的手机");
				return;
			}


			document.getElementById("form1").submit();

		}
	</script>



</html>
